# -*- coding: utf-8 -*-
# @Time : 2021/9/17 15:01
# @Author : hello
# @Email : xxx@gmail.com
# @File : MRSX_ST_FL_002.py
# @Project : mryx_test


"""验证每日优鲜-验证删除搜索记录功能"""

from appium import webdriver
from selenium.webdriver.common import desired_capabilities
from appium.webdriver.common.mobileby import MobileBy as By
from selenium.webdriver.support.wait import WebDriverWait
from time import sleep

desired_capabilities={
    "platformName":"Android",
    "deviceName":"127.0.0.1:62025",
    "platformVersion":"5.1.1",
    "appPackage":"cn.missfresh.application",
    "appActivity":"cn.missfresh.module.base.main.view.MainActivity",
    "noReset":"True"
}
driver=webdriver.Remote("http://localhost:4723/wd/hub",desired_capabilities)
try:
    #点击分类-进入分类页
    driver.implicitly_wait(30)
    fl=(By.ANDROID_UIAUTOMATOR,'new UiSelector().text("分类")')
    driver.find_element(*fl).click()
    #点击搜索
    ss= (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("搜索")')
    driver.find_element(*ss).click()
    #搜索框输入内容
    nr=(By.XPATH,'//android.widget.EditText[@resource-id=\"cn.missfresh.application:id/search_view\"]')
    driver.find_element(*nr).send_keys("肉蛋")
    sleep(4)
    #点击搜索
    ssnr=(By.XPATH,'//android.widget.TextView[@resource-id=\"cn.missfresh.application:id/tv_search\"]')
    driver.find_element(*ssnr).click()
    sleep(3)
    #返回搜索界面
    driver.keyevent(4)
    sleep(3)
    # 点击搜索
    driver.tap([(15,53),(705,101)])
    sleep(3)
    #点击删除
    sc=(By.XPATH,'//android.widget.ImageView[@resource-id=\"cn.missfresh.application:id/clear_his_view\"]')
    driver.find_element(*sc).click()
    sleep(3)
    #确定清空
    qk=(By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("清空")')
    driver.find_element(*qk).click()
    #断言
    # qd = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("热门搜索")')


except Exception as e:
    raise e
finally:
    sleep(3)
    # driver.quit()